package com.cdty.chess.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/api/v1/apiStream")
public class StreamController {

    @Autowired
    NamedParameterJdbcTemplate template;

    @GetMapping("/createStream")
    public Map<String, String> createStream() {
        String streamId = UUID.randomUUID().toString().substring(0, 6);
        return Map.of("streamId", streamId);
    }

    // 增加确认接口
    @GetMapping("/confirmMessage")
    public void confirmMessage(@RequestParam String msgId) {
        String sql = "UPDATE sse_message SET status = 1 WHERE id = :msgId";
        template.update(sql, new MapSqlParameterSource("msgId", msgId));
    }
}